{extend name="common/layout" /}
{block name="main"}
<div class="admin-main layui-anim layui-anim-upbit">

   <div class="padding30">
        <h3 class="page-box-title">{$title}</h3>
        <div class="demoTable">
            <div class="layui-inline">
                <input class="layui-input layui-search-input" name="key" style="width: 250px" id="key" placeholder="{:lang('Username / mailbox/ phone')}">
            </div> 
            <button class="layui-btn layui-search-btn borderrad5" id="search" data-type="reload">{:lang('Search')}</button>
            <a class="layui-btn layui-btn-warm borderrad5" id="downReport" href="{$repotUrl}" target="_blank">{:lang('Export')}</a>
            <div style="clear: both;"></div>
        </div>
         
    </div>
     <div class="" id="_listBox">
        <div style="text-align: right;"><a href="{$addUrl}"   class="layui-btn layui-btn-normal layui-btn-add borderrad5 " title="{:lang('Add')}" ><i class="icon icon-plus"></i></a></div>

    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
</div>

{/block}
{block name='footer'}
<script type="text/html" id="barDemo">
    <a href="{$editUrl}?admin_id={{d.admin_id}}" class="">{:lang('Edit')}</a> | 
    {{# if(d.admin_id==1){ }}
    <a href="#" class="layui-btn-disabled disabled-back">{:lang('Delete')}</a>
    {{# }else{  }}
    <a class="" lay-event="del" href="#">{:lang('Delete')}</a>
    {{# } }}
</script>
<script type="text/html" id="open">
    {{# if(d.admin_id==1){ }}
        <input type="checkbox" disabled name="is_open" value="{{d.admin_id}}" lay-skin="switch" lay-text="{:lang('No|Off')}" lay-filter="open" checked>
    {{# }else{  }}
        <input type="checkbox" name="is_open" value="{{d.admin_id}}" lay-skin="switch" lay-text="{:lang('No|Off')}" lay-filter="open" {{ d.is_open == 1 ? 'checked' : '' }}>
    {{# } }}
</script>
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery;
        var tableIn = table.render({
            elem: '#list',
            url: "{$requestUrl}",
            method:'post', 
            page:getPageThume(),
            cols: [[
                // {field:'username', title: "{:lang('User Name')}", width:"10%",fixed: true}
                
                {field:'email', title: "{:lang('Mailbox')}", width:"20%",sort:true}
                ,{field:'guishu', title: "{:lang('User Ownership')}", width:"12%"}
                ,{field:'title', title: '{:lang("User Group")}', width:"12%"}
                ,{field:'mobile', title: '{:lang("Mobile")}', width:"12%"}
                ,{field:'is_open', title: '{:lang("status")}',width:"10%",toolbar: '#open'}
                ,{width:"13%", align:'center', toolbar: '#barDemo',align:"right"}
            ]]
        });
         //搜索
        $('#search').on('click', function () {
            var key = $('#key').val();
            tableIn.reload({
                where: {key: key},
                done: function(res, curr, count){
                    console.log(res);
                    $("#downReport").attr("href",res.repotUrl);
                }
            });

        });
        form.on('switch(open)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var is_open = obj.elem.checked===true?1:0;
            $.post('{:url("adminState")}',{'id':id,'is_open':is_open},function (res) {
                layer.close(loading);
                if (res.status==1) {
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        });
        table.on('tool(list)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('{:lang("Are you sure you want to delete it")}', function(index){
                    loading =layer.load(1, {shade: [0.1,'#fff']});
                    $.post("{:url('adminDel')}",{admin_id:data.admin_id},function(res){
                        layer.close(loading);
                        if(res.code==1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });

    });
</script>
{/block}